package org.drl.tvkit.widget;

import org.drl.tvkit.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.RelativeLayout;

/**
 * @author Darry Ring
 * 
 */
public class MovieLayout extends RelativeLayout {

	private Animation scaleSmallAnimation;
	private Animation scaleBigAnimation;

	public MovieLayout(Context context) {
		super(context);
		init();
	}

	public MovieLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public MovieLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	protected void init() {
	}
	@Override
	public void setSelected(boolean selected) {
		super.setSelected(selected);
		clearAnimation();
		if (selected) {
			bringToFront();
			zoomOut();
		} else {
			zoomIn();
		}
	}
	private void zoomIn() {
		if (scaleSmallAnimation == null) {
			scaleSmallAnimation = AnimationUtils.loadAnimation(getContext(),
					R.anim.anim_scale_small);
		}
		startAnimation(scaleSmallAnimation);
	}
	@Override
	protected void onAnimationEnd() {
		super.onAnimationEnd();
		postInvalidate();
	}
	
	@Override
	protected void onAttachedToWindow() {
		super.onAttachedToWindow();
	}

	private void zoomOut() {
		if (scaleBigAnimation == null) {
			scaleBigAnimation = AnimationUtils.loadAnimation(getContext(),
					R.anim.anim_scale_big);
		}
		startAnimation(scaleBigAnimation);
	}

}
